home *** CD-ROM | disk | FTP | other *** search
- Path: odi.com!usenet
- From: Kimberley Burchett <burchett>
- Newsgroups: comp.lang.c++
- Subject: Re: Aborting Constructors, Part II
- Date: 1 Feb 1996 22:36:02 GMT
- Organization: Software Leverage, Inc
- Message-ID: <4erf8i$g0b@mastermind.odi.com>
- References: <4eoeck$t6n@news.ios.com>
- NNTP-Posting-Host: loon.odi.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.3 sun4c)
- X-URL: news:4eoeck$t6n@news.ios.com
-
- leonardj@tribeca.ios.com (John Leonard) wrote:
- >
- > Earlier, I posted a message about aborting a constructor if for some
- >reason some resource cannot be allocated. I did some thinking about
- >the problem and I thought, why couldn't you just call 'delete' inside
- >of the constructor itself and then let the destructor take care of the
- >release of all resources allocated so far.
-
- 1) it requires that the object was allocated with new. If the object is
- on the stack or in an STL container, this will not work.
-
- 2) if the constructor is being called as part of constructing a derived
- class, then once the base class constructor is done, the derived class's
- constructor takes over and will most likely not realize that "this" is no
- longer valid.
-
- 3) there is no way for the creator of the object to know whether the
- object it just created is usable. It also doesn't know whether it should
- delete the object or the object has already deleted itself. You can't
- ask the object whether it's usable because the object may not exist any
- more.
-
- The Microsoft Foundation Classes do use "delete this" when destroying
- modeless dialogs. Basically they use it as a kind of garbage collection;
- they can create a modeless dialog on the heap without storing the
- pointer, and the window will destroy itself as soon as it closes. But
- this happens *after* the user is done with the window -- *not* before
- the window is created.
-
- Kimberley
-
-